package <%= config.basePackage %>controller;

<% if(config.swagger === "knife4j") {%>
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
<%}%>
import <%= config.basePackage %>common.Result;
import <%= config.basePackage %>entity.<%= table.className %>;
import <%= config.basePackage %>service.<%= table.className %>Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
* @author <%= config.author %>
* @date  <%= config.date %>
* @description <%= table.tableName %> <%= table.tableComment %>控制器
* Generated By: uToolsPlugin SqlConvert
* Lesscoding Generate Service
* @version: 0.0.5
* Link to: <a href="https://lesscoding.net">https://lesscoding.net</a>
* mail to:2496290990@qq.com
*/
@RestController
@RequestMapping("/<%= table.firstLowerClassName %>")
<% if(config.swagger === "knife4j") { %>
    @Api(tags = "<%= table.tableComment %>")
<% } %>
public class <%= table.className %>Controller{

    @Autowired
    private <%= table.className %>Service <%= table.firstLowerClassName %>Service;

    @GetMapping("/page")
    <% if(config.swagger === "knife4j") { %>
        @ApiOperation(value = "分页查询<%= table.tableComment %>数据",notes = "分页查询描述")
    <% } %>
    public Result getPageByLike(<%= table.className %> <%= table.firstLowerClassName %>){
        return Result.success(<%= table.firstLowerClassName %>Service.getPageByLike(<%= table.firstLowerClassName %>));
    }

    @GetMapping("/{id}")
    <% if(config.swagger === "knife4j") { %>
        @ApiOperation(value = "根据id查询<%= table.tableComment %>",notes = "详情查询描述")
    <% } %>
    public Result get<%= table.className %>ById(@PathVariable("<%= primaryKey.field%>") <%= primaryKey.javaType%> <%= primaryKey.field%>){
        return Result.success(<%= table.firstLowerClassName %>Service.getById(<%= primaryKey.field%>));
    }

    @PostMapping("/edit")
    <% if(config.swagger === "knife4j") { %>
        @ApiOperation(value = "编辑<%= table.tableComment %>",notes = "编辑描述")
    <% } %>
    public Result edit<%= table.className %>ById(@RequestBody <%= table.className %> <%= table.firstLowerClassName %>){
        return Result.buildByResult(<%= table.firstLowerClassName %>Service.edit<%= table.className %>(<%= table.firstLowerClassName %>));
    }

    /**
    * 当前为逻辑删除，
    * 需要在实体类逻辑删除字段上添加 @TableLogic(value = "1",delval = "0")
    * 对应你的逻辑删除值，
    * 真删除调用delById(id)即可
    * @param id
    * @return
    */
    @DeleteMapping("/{id}")
    <% if(config.swagger === "knife4j") { %>
        @ApiOperation(value = "根据id删除<%= table.tableComment %>",notes = "根据id删除")
    <% } %>
    public Result del<%= table.className %>ById(@PathVariable("<%= primaryKey.field%>") <%= primaryKey.javaType%> <%= primaryKey.field%>){
        return Result.buildByResult(<%= table.firstLowerClassName %>Service.removeById(<%= primaryKey.field%>));
    }
    <% if(config.exportFlag) {%>
        @GetMapping("/template")
        <% if(config.swagger === "knife4j") { %>
            @ApiOperation(value = "下载<%= table.tableComment %>导入模板")
        <% } %>
        public void downloadTemplate(HttpServletResponse response){
            <%= table.firstLowerClassName %>Service.downloadTemplate(response);
        }

        @PostMapping("/import")
        <% if(config.swagger === "knife4j") { %>
            @ApiOperation(value = "从Excel模板导入<%= table.tableComment %>数据")
        <% } %>
        public Result import4Excel(MultipartFile file){
            return Result.success(<%= table.firstLowerClassName %>Service.import4Excel(file));
        }

        @PostMapping("/export")
        <% if(config.swagger === "knife4j") { %>
            @ApiOperation(value = "导出<%= table.tableComment %>列表数据到Excel表格")
        <% } %>
        public void export2Excel(@RequestBody <%= table.className %> <%= table.firstLowerClassName %>,HttpServletResponse response){
            <%= table.firstLowerClassName %>Service.export2Excel(<%= table.firstLowerClassName %>,response);
        }
    <% } %>
}
